home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14323 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  67 lines

  1. Path: ix.netcom.com!news
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Is WATCOM 10.5 a broken compiler or am I stupid?
  5. Date: 29 Mar 1996 16:47:10 GMT
  6. Organization: Netcom
  7. Message-ID: <4jh46e$scq@dfw-ixnews6.ix.netcom.com>
  8. References: <315A8A29.613B4EBA@rz.tu-ilmenau.de>
  9. NNTP-Posting-Host: den-co11-03.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Fri Mar 29 10:47:10 AM CST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. In article <315A8A29.613B4EBA@rz.tu-ilmenau.de>, ai108@rz.tu-ilmenau.de 
  16. says...
  17. >typedef struct cstringTEMP
  18. >{
  19. > char len;
  20. > char data[255];
  21. > public:
  22. > cstringTEMP & operator=(char *);
  23. >} cstring;
  24. >
  25. >AND THIS IS THE CODE I TRIED TO USE:
  26. >
  27. > cstring cs="test";
  28. >
  29. >
  30. >IT GAVE THIS ERROR-MESSAGE:
  31. >Error! E400: (col 13) cannot convert right expression for initialization 
  32. >
  33. >CHANGING THE LINE ABOVE TO:
  34. >cstring cs;
  35. >cs="test";
  36. >AND THE ERROR WAS NOT LONGER THERE.
  37.  
  38.  
  39. Writing:
  40.     cstring cs = "test";
  41. Attempts to construct a cstring using "test" as an argument to
  42. the constructor.  You have no constructor taking (char*), so this
  43. fails.
  44.  
  45. Writing
  46.     cstring cs;
  47.     cs = "test";
  48. Calls the default constructor for cstring, and then uses operator=
  49. to assign "test" to it.
  50.  
  51.  
  52. To make
  53.     csstring cs = "test"
  54. work, add a constructor to cstring
  55.  
  56.     typedef struct cstringTEMP
  57.     {
  58.        char len;
  59.        char data[255];
  60.        public:
  61.          cstringTEMP & operator=(char *);
  62. -->         cstring(const char*s) { strcpy(data, s); len = strlen(s); }
  63.     } cstring;
  64.  
  65. john lilley
  66.  
  67.